﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ulement.Web;
using System.IO;
using System.Data;

public partial class MasterPage : System.Web.UI.MasterPage
{
    public int lang = 2;
    public string m_logo;
    public string m_footer;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["lang"] != "" && Request.QueryString["lang"] != null) lang = Convert.ToInt32(Request.QueryString["lang"]);

        if (!this.IsPostBack)
        {
            LoadLoaiGioiThieu();
            LoadLoaiToChuc();
            LoadLoaiTinTuc();
            if (lang == 1)
            {
                lbDoitac.Text = "Đối tác & Khách hàng";
                lbDieuKhoan.Text = "Điều khoản";
                lbChinhSach.Text = "Chính sách";
                lbTuyenDung.Text = "Tuyển dụng";
                lbLienHe.Text = "Liên hệ";
                lbltrangchu.Text = "Trang chủ";
            }
            else
            {
                lbDoitac.Text = "Partners & Clients";
                lbDieuKhoan.Text = "Legal";
                lbChinhSach.Text = "Privacy";
                lbTuyenDung.Text = "Recruitment";
                lbLienHe.Text = "Contact Us";
                lbltrangchu.Text = "Home";
            }

            TrangTinhDataSet TrangTinhds = new TrangTinhDataSet();
            TrangTinhHelper TrangTinhhelper = new TrangTinhHelper();
            TrangTinhds = TrangTinhhelper.LoadTrangTinhViTri("Logo", 1);


            if (!TrangTinhds.TrangTinh[0].IsNoiDungNull()) m_logo = TrangTinhds.TrangTinh[0].NoiDung;

            TrangTinhDataSet TrangTinhdsfooter = TrangTinhhelper.LoadTrangTinhViTri("Footer", lang);
            if (!TrangTinhdsfooter.TrangTinh[0].IsNoiDungNull()) m_footer = TrangTinhdsfooter.TrangTinh[0].NoiDung;

        }
    }

    private void LoadLoaiGioiThieu()
    {
        lbGioiThieu.Text = "About us";
        if (lang == 1) lbGioiThieu.Text = "Giới thiệu";

        System.Data.DataTable oTable = new System.Data.DataTable();
        oTable.Columns.Add(new System.Data.DataColumn("key"));
        oTable.Columns.Add(new System.Data.DataColumn("value"));

        foreach (System.Collections.DictionaryEntry oEntry in LoaiDataHelper.LoadLoaiGioiThieu(lang))
        {
            DataRow oDataRow = oTable.NewRow();
            oDataRow["key"] = oEntry.Key;
            oDataRow["value"] = oEntry.Value;
            oTable.Rows.Add(oDataRow);
        }

        DataView oDataView = new DataView(oTable);
        oDataView.Sort = "value asc, key ASC";

        repLoaiGioiThieu.DataSource = oDataView;
        repLoaiGioiThieu.DataBind();
    }

    private void LoadLoaiToChuc()
    {
        lbToChuc.Text = "Company";
        if (lang == 1) lbToChuc.Text = "Tổ chức";
        repToChuc.DataSource = LoaiDataHelper.LoadLoaiToChuc();
        repToChuc.DataBind();
    }

    private void LoadLoaiTinTuc()
    {
        lbTinTuc.Text = "Hot news";
        if (lang == 1) lbTinTuc.Text = "Tin tức";
        repTinTuc.DataSource = LoaiDataHelper.LoadLoaiTinTuc(lang);
        repTinTuc.DataBind();
    }

    public string LinkGioiThieuDetail(object ID)
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "GioiThieuDetail.aspx?loai=" + ID + "&lang=" + tukhoa;
    }

    public string LinkToChucDetail(object ID)
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "ToChucDetail.aspx?loai=" + ID + "&lang=" + tukhoa;
    }

    public string LinkTinTucDetail(object ID)
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "News.aspx?loai=" + ID + "&lang=" + tukhoa;
    }
    public string LinkDoiTac()
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "DoiTac.aspx?lang=" + tukhoa;
    }
    public string LinkNgonNgu(int ID)
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        ur.Set("lang", ID.ToString());

        return Path.GetFileName(Request.Path)+ur;
    }

    public string LinkDieuKhoan()
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "DieuKhoan.aspx?lang=" + tukhoa;
    }

    public string LinkChinhSach()
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "ChinhSach.aspx?lang=" + tukhoa;
    }

    public string LinkLienHe()
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "LienHe.aspx?lang=" + tukhoa;
    }

    public string LinkTuyenDung()
    {

        HttpUrlQuery ur = new HttpUrlQuery(Page.Request.QueryString);
        string tukhoa = ur.Get("lang");

        return "TuyenDung.aspx?lang=" + tukhoa;
    }
}
